home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1994 #2
/
Monster Media No. 2 (Monster Media)(1994).ISO
/
math
/
eval30.zip
/
EVAL.DOC
< prev
next >
Wrap
Text File
|
1994-07-02
|
8KB
|
216 lines
EVAL 3.0 - 7/2/94
The DOS Expression evaluator
By: Terry A. Reagan
WHAT IS EVAL?
EVAL is a DOS expression evaluator. EVAL could be thought of as a
command line calculator. It allows you to get immediate answer to
calculations directly from the command line.
For example, to calculate the area of a circle 2.4 feet in diameter, you
could type:
EVAL pi*2.4^2
and would get the answer as 18.0955736846772091 square feet.
Syntax is: EVAL expression[,format]
AVAILABLE OPERATORS
Arithmetic operators:
+ Addition - Subtraction
* Multiplication / Division
^ Exponentiation % Remainder (MOD)
Bitwise operators:
& Logical AND | Logical OR
@ Logical XOR
Special Operators:
? Roll and add
() Parentheses are used to enclose other operations.
Functions:
SIN,COS,TAN Trig functions
ASIN, ACOS, ATAN Inverse SIN,COS,TAN
EXP,LN e^x, Log base e
LOG Log base 10
SQRT Square root of x
ABS Absolute value
ERF Error function
Constants:
e = 2.718281828459045235
pi = 3.141592653589793238
Formats:
Formats determine how the number is displayed.
x = Hex
b = Binary
10 = Decimal
8 = Octal
p = Programmer format. The number is displayed in
decimal, and is followed by a hex representation
of the 10 byte internal format.
p4 = Programmer format displaying 4 byte floats.
p8 = Programmer format displaying 8 byte floats.
For other base between 2 and 36, the value
can be used. For example, to show 1 million
in base 36, type:
EVAL 1000000,36
Number prefixes:
0x specifies a hex number.
0b specifies a binary number.
GENERAL COMMENTS AND NOTES ABOUT USING EVAL
- All trig functions work in radians, not degrees.
- The | symbol is not valid on a DOS command line
unless inside quotes, so if you want to use the
bitwise "OR" function, type
EVAL "22|55" instead of EVAL 22|55
Otherwise, DOS thinks you are calling EVAL 22
and piping the result to a program called 55.
To show this result in hex, type
EVAL "22|55",x
- "Roll and add" is a function used for certain games. Ever wanted
to roll a 9 sided die? Now you can. Type
EVAL 1?9
If you wish to roll three normal (6 sided) dice and add the result, type
EVAL 3?6
This will "roll" three six-sided dice and add the results.
- All numbers are stored as 80 bit floating point numbers. (C long doubles).
In all cases, I try to maintain precision.
- EVAL follows normal algebraic rules for precedence. That is, operations
inside () happen first. If there are no (), exponentiation occurs before
multiplication and division. Multiplication and division occur before
addition and subtraction.
- EVAL was written and compiled using Microsoft Visual C++ V1.0.
SPECIAL NOTES TO PROGRAMMERS
One of the most valuable features of EVAL is the ability to handle very
large numbers in hex, decimal and binary. Most of the commercial
calculators I have seen can only handle 4 byte hex numbers. On several
occasions, I found this to be inadequate. EVAL stores ALL numbers as
10 byte floating point numbers, so you can do hex calculations with
larger numbers and with higher precision. You can also display the
fractional portion of non-integers in hex, or display the internal
representation of floating point numbers.
EXAMPLES
Calculate the sum of 2,3,5,7 and 11.
EVAL 2+3+5+7+11
Find 2 to the power of (3+7).
EVAL 2^(3+7)
Find the sum of 12 eight-sided dice rolled randomly
and add 2 to the result.
(For RPG players, this is 12d8+2)
EVAL 12?8+2
Find the TAN of 30 degrees.
EVAL TAN(30*PI/180)
Convert the number 123,456 to hex.
EVAL 123456,x
Convert the number 500 to binary.
EVAL 500,b
Convert the number 10000 to base 4.
EVAL 10000,4
Convert the hex number 01AB to decimal.
EVAL 0x1AB
(Note: decimal is the default format.)
Convert the hex number 12 to binary
EVAL 0x12,b
Add the hex number 100 to the decimal number 100
EVAL 0x100+100
Show PI in hex
EVAL PI,x
PROGRAMMER EXAMPLES
What is 123,456,789,012,345,678 in hex?
EVAL 123456789012345678,x
What is the decimal value of the hex number 1AABBCCDDEEFF?
EVAL 0x1AABBCCDDEEFF
What is the internal represation of pi as a 10 byte floating point number?
As an 8 byte floating point number?
As a 4 byte floating point number?
EVAL pi,p
EVAL pi,p8
EVAL pi,p4
HISTORY
Eval was written by Terry A. Reagan.
EVAL has been an ongoing project since 1985. I have added features as
needed.
8/09/85 Version 1.0 handles simple operators +,-,*,/, and ().
2/18/86 Added functions including TRIG, LOG, and ERF functions.
Version 1.1
4/14/91 Added roll function.
Version 1.2
6/29/91 Added bitwise operators.
Added option to print results in hex
Added option to input number in hex and binary.
Added option to print in bases other than hex.
Version 2.0
6/05/93 Pulled out high-speed table driven parser and replaced with
much smaller and slower C parser.
Convert the entire program to C++.
Version 2.1
7/02/94 Code clean up and documentation in preparation for Shareware
release.
Programmer formats added to displaying the actual bytes which
make up the number as stored.
Version 3.0 is initial shareware release
POSSIBLE FUTURE ENHANCEMENTS
- Add hyperbolic functions. (SINH, COSH, TANH,...)
- Allow entering numbers of any base.
- Better error handling when a library function fails.
- Make a better/smarter/faster version of the roll function using ERF.
PAYMENT OF SHAREWARE FEES
There are no required fees. If you find EVAL to be useful, or if your
conscience is getting the better of you and you feel compelled to pay
something, do one or more of the following:
1) Send me a copy of your favorite SHAREWARE or FREEWARE utility
or game. (Please don't send me pirated software.)
2) Send me a note telling how you are using EVAL and what I can do
to improve it for your particular use.
3) Donate money to the American Heart Association, National Cancer
Society, Aids Foundation, Diabetic Society, or some other equally
worthy cause.
DISTRIBUTION AND COPYRIGHTS
The program EVAL is copyrighted 1985-1994 by Terry A. Reagan.
You may copy, distribute and use this program free of charge, but:
You must not charge for copying or distributions, other
than a nominal charge for media, materials and postage.
If you distribute EVAL, you must distribute the entire
package without modification. This includes:
EVAL.EXE, EVAL.DOC, DEMO.BAT
CONTACTING THE AUTHOR
The program EVAL was written by Terry A. Reagan.
If you are using EVAL and have found it to be useful, I would love to
hear from you. If you have any ideas of suggestions, please let me know.
I can be reached at
CompuServe: 76520,464
Internet: 76520.464@compuserve.com
Prodigy: GWSF28A
I hope you find this program useful.
Terry (-t)